﻿using System;
using System.Collections.Generic;
using System.Drawing.Drawing2D;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.DB;
using YJKStairs.CommonUnit;
using YJKStairs.DataInfos;

namespace YJKStairs.Kit
{
	internal class LinearSingleRunStairsKit : ProjectionDrawingKit
	{
		public LinearSingleRunStairsKit(Autodesk.Revit.ApplicationServices.Application app) : base(app)
		{
		}

		public bool LinearSingleRunStairsProfileCurves(ref LinearSingleRunStairs stairs, bool bDrawNoteInfo, int basePointIndex, bool lrMirror, bool tbMirror, bool bBottomUp, double rotateAngle, bool bBottom, bool bTop)
		{
			bool result = true;
			LineRunData runData = stairs.m_RunData;
			double dStairsWidth = stairs.m_dStairsWidth;
			double dStairsLength = stairs.m_dStairsLength;
			List<XYZ> list = new List<XYZ>();
			XYZ zero = XYZ.Zero;
			XYZ xyz = new XYZ(runData.RunWidth, 0.0, 0.0);
			XYZ xyz2 = new XYZ(0.0, runData.RunLength, 0.0);
			XYZ xyz3 = new XYZ(runData.RunWidth, runData.RunLength, 0.0);
			stairs.m_RunData.PtRunBottomLeft = zero;
			stairs.m_RunData.PtRunBottomRight = xyz;
			stairs.m_RunData.PtRunTopLeft = xyz2;
			stairs.m_RunData.PtRunTopRight = xyz3;
			stairs.m_listPointsSupport.Add(zero);
			stairs.m_listPointsSupport.Add(xyz2);
			list.Add(zero);
			list.Add(xyz2);
			list.Add(xyz3);
			list.Add(xyz);
			XYZ xyz4 = list[basePointIndex];
			base.CalulateTransform(lrMirror, tbMirror, rotateAngle, dStairsWidth, dStairsLength, xyz4);
			stairs.m_TransVector = Geometry.TransformPoint(xyz4, this.m_Transform);
			stairs.m_listOtherCurve.AddRange(base.DrawBasePoint(xyz4, 100.0));
			stairs.m_Transform = this.m_Transform;
			this.DrawLinearSingleRunStairsRunCurves(ref stairs, bBottomUp, bDrawNoteInfo);
			this.DrawLinearSingleRunStairsBeamCurves(ref stairs, bBottomUp, bBottom, bTop);
			this.DrawLinearSingleRunStairsNoteInfo(ref stairs);
			if (bDrawNoteInfo)
			{
				this.DrawUpStairsNoteInfo(ref stairs, bBottomUp);
			}
			return result;
		}

		private void DrawLinearSingleRunStairsRunCurves(ref LinearSingleRunStairs param_stairs, bool bBottomUp, bool bDrawNoteInfo)
		{
			if (param_stairs != null)
			{
				LineRunData runData = param_stairs.m_RunData;
				if (bBottomUp)
				{
					SingleRunCurveInfo singleRunCurveInfo = new SingleRunCurveInfo();
					singleRunCurveInfo.BottomElevation = runData.BottomElevation;
					base.DrawLinearRun(runData, runData.PtRunBottomLeft, runData.PtRunBottomRight, runData.PtRunTopRight, runData.PtRunTopLeft, ref singleRunCurveInfo, ref param_stairs.m_listOtherCurve, bDrawNoteInfo);
					param_stairs.m_listRunCurve.Add(singleRunCurveInfo);
					return;
				}
				SingleRunCurveInfo singleRunCurveInfo2 = new SingleRunCurveInfo();
				singleRunCurveInfo2.BottomElevation = runData.BottomElevation;
				base.DrawLinearRun(runData, runData.PtRunTopRight, runData.PtRunTopLeft, runData.PtRunBottomLeft, runData.PtRunBottomRight, ref singleRunCurveInfo2, ref param_stairs.m_listOtherCurve, bDrawNoteInfo);
				param_stairs.m_listRunCurve.Add(singleRunCurveInfo2);
			}
		}

		private void DrawLinearSingleRunStairsBeamCurves(ref LinearSingleRunStairs param_stairs, bool bBottomUp, bool bBottom, bool bTop)
		{
			if (param_stairs != null)
			{
				double num = param_stairs.m_BeamData.BeamWidth / 2.0;
				LineRunData runData = param_stairs.m_RunData;
				double bottomElevation = runData.BottomElevation;
				XYZ ptS = XYZ.Zero;
				XYZ ptE = XYZ.Zero;
				XYZ xyz = new XYZ(0.0, num, 0.0);
				if (bBottomUp)
				{
					if (bBottom)
					{
						List<CurveInfo> list = new List<CurveInfo>();
						ptS = runData.PtRunBottomLeft - xyz;
						ptE = runData.PtRunBottomRight - xyz;
						list.Add(base.NewLine(PenColor.PC_Gray, DashStyle.Solid, 1f, ptS, ptE, xyz));
						BeamCurveInfo beamCurveInfo = new BeamCurveInfo(list, bottomElevation);
						beamCurveInfo.m_Type = BeamType.BT_Bottom;
						beamCurveInfo.m_nFloorNum = 0;
						param_stairs.m_listBeamCurve.Add(beamCurveInfo);
					}
					if (bTop)
					{
						List<CurveInfo> list2 = new List<CurveInfo>();
						ptS = runData.PtRunTopLeft + xyz;
						ptE = runData.PtRunTopRight + xyz;
						list2.Add(base.NewLine(PenColor.PC_Gray, DashStyle.Solid, 1f, ptS, ptE, xyz));
						BeamCurveInfo beamCurveInfo2 = new BeamCurveInfo(list2, bottomElevation);
						beamCurveInfo2.m_Type = BeamType.BT_Top;
						beamCurveInfo2.m_nFloorNum = 0;
						param_stairs.m_listBeamCurve.Add(beamCurveInfo2);
						return;
					}
				}
				else
				{
					if (bBottom)
					{
						List<CurveInfo> list3 = new List<CurveInfo>();
						ptS = runData.PtRunTopLeft + xyz;
						ptE = runData.PtRunTopRight + xyz;
						list3.Add(base.NewLine(PenColor.PC_Gray, DashStyle.Solid, 1f, ptS, ptE, -xyz));
						BeamCurveInfo beamCurveInfo3 = new BeamCurveInfo(list3, bottomElevation);
						beamCurveInfo3.m_Type = BeamType.BT_Bottom;
						beamCurveInfo3.m_nFloorNum = 0;
						param_stairs.m_listBeamCurve.Add(beamCurveInfo3);
					}
					if (bTop)
					{
						List<CurveInfo> list4 = new List<CurveInfo>();
						ptS = runData.PtRunBottomLeft - xyz;
						ptE = runData.PtRunBottomRight - xyz;
						list4.Add(base.NewLine(PenColor.PC_Gray, DashStyle.Solid, 1f, ptS, ptE, -xyz));
						BeamCurveInfo beamCurveInfo4 = new BeamCurveInfo(list4, bottomElevation);
						beamCurveInfo4.m_Type = BeamType.BT_Top;
						beamCurveInfo4.m_nFloorNum = 0;
						param_stairs.m_listBeamCurve.Add(beamCurveInfo4);
					}
				}
			}
		}

		private void DrawLinearSingleRunStairsNoteInfo(ref LinearSingleRunStairs param_stairs)
		{
			LineRunData runData = param_stairs.m_RunData;
			XYZ xyz = XYZ.BasisY * 2.0;
			XYZ xyz2 = XYZ.BasisX * 2.0;
			XYZ xyz3 = XYZ.Zero;
			XYZ ptEnd = XYZ.Zero;
			xyz3 = runData.PtRunTopLeft + xyz;
			ptEnd = runData.PtRunTopRight + xyz;
			base.DrawStairsNoteInfo(ref param_stairs.m_listOtherCurve, ref param_stairs.m_listText, xyz3, ptEnd, "梯段宽度", 0.8, 5.0, 2.0, XYZ.BasisY, PenColor.PC_Black);
			xyz3 = runData.PtRunTopLeft - xyz2;
			ptEnd = runData.PtRunBottomLeft - xyz2;
			base.DrawStairsNoteInfo(ref param_stairs.m_listOtherCurve, ref param_stairs.m_listText, xyz3, ptEnd, "梯段长度", 0.8, 2.0, 5.0, -XYZ.BasisX, PenColor.PC_Black);
			XYZ xyz4 = new XYZ(0.0, runData.TreadDepth, 0.0);
			xyz3 = runData.PtRunBottomRight + xyz2;
			ptEnd = xyz3 + xyz4;
			base.DrawStairsNoteInfo(ref param_stairs.m_listOtherCurve, ref param_stairs.m_listText, xyz3, ptEnd, "踏步宽度", 0.8, 2.0, 5.0, XYZ.BasisX, PenColor.PC_Black);
		}

		private void DrawUpStairsNoteInfo(ref LinearSingleRunStairs param_stairs, bool bBottomUp)
		{
			LineRunData runData = param_stairs.m_RunData;
			XYZ xyz = XYZ.BasisY * 1.0;
			List<UpDownText> list = new List<UpDownText>();
			string sText = "上";
			if (bBottomUp)
			{
				XYZ pos = Geometry.CalculatMidPoint(runData.PtRunBottomLeft, runData.PtRunBottomRight) - xyz;
				UpDownText item = new UpDownText(pos, sText);
				list.Add(item);
				item = new UpDownText(pos, sText);
				list.Add(item);
				base.DrawUpDownNoteInfo(ref param_stairs.m_listText, list);
				return;
			}
			XYZ pos2 = Geometry.CalculatMidPoint(runData.PtRunTopLeft, runData.PtRunTopRight) + xyz;
			UpDownText item2 = new UpDownText(pos2, sText);
			list.Add(item2);
			item2 = new UpDownText(pos2, sText);
			list.Add(item2);
			base.DrawUpDownNoteInfo(ref param_stairs.m_listText, list);
		}
	}
}
